﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.JinShengService;
using CommunitySystem.PageView.晋升管理;

namespace CommunitySystem.PageView
{
    public partial class EditJinshengControl : UserControl
    {
       public bool ReturnTrue = false;
       private string isqx = "";
       private bool _isck = false;
       public EditJinshengControl(JinShen_MainInfo entity, string qx, int orgid, bool isck, string jmstatus)
        {
            InitializeComponent();
            _isck = isck;
            this.DataContext = entity;
            _orgid = orgid;
            isqx = qx;
            if (isck)
                btnqx.Content = "查看";
            else
            {
            if (qx == JinShenConst.ACTION_Solution_Modify)
            {
                if (entity.Status == "审核通过")
                    btnqx.Content = "查看";
                else this.btnqx.Content = "编辑";
            }
            if (qx == JinShenConst.ACTION_Solution_Check)
            {
               // if ((entity.Status == "审核通过" || entity.Status == "审核不通过") && jmstatus != "再次申请")
                if (entity.Status == "审核通过")
                    btnqx.Content = "查看";
                else
                this.btnqx.Content = "审核";
            }
            if (qx == JinShenConst.ACTION_Candidate_New)
            {
                if ((entity.Status == "人员审核通过"))
                    btnqx.Content = "查看";
                else this.btnqx.Content = "增加候选人";
            }
            if (qx == JinShenConst.ACTION_Candidate_Check)
            {
                if (entity.Status == "人员审核通过" || entity.Status == "人员审核不通过")
                    btnqx.Content = "查看";
                else
                this.btnqx.Content = "人员审核";
            }
            if (qx == JinShenConst.ACTION_Candidate_Evalution)
                this.btnqx.Content = "民主测评及竞争上岗";
            if (qx == JinShenConst.ACTION_Candidate_Approval)
                this.btnqx.Content = "人员核定";
            }
          
        }

        private string _bm = "";
        private int _orgid = -1;
        public EditJinshengControl(JinShen_MainInfo entity, string qx,string bm,int orgid,bool isck,string jmstatus)
        {
            InitializeComponent();
            _isck = isck;
            _bm = bm;
            _orgid = orgid;
            this.DataContext = entity;
            isqx = qx;
            if (isck)
                btnqx.Content = "查看";
            else
            {
                if (qx == JinShenConst.ACTION_Solution_Modify)
                {
                    if (entity.Status == "审核通过")
                        btnqx.Content = "查看";
                    else this.btnqx.Content = "编辑";
                }
                if (qx == JinShenConst.ACTION_Solution_Check)
                {
                  //  if ((entity.Status == "审核通过" || entity.Status == "审核不通过") && jmstatus != "再次申请")
                         if (entity.Status == "审核通过")
                    btnqx.Content = "查看";
                    
                    else this.btnqx.Content = "审核";
                }
                if (qx == JinShenConst.ACTION_Candidate_New)
                {
                    if ((entity.Status == "人员审核通过"))
                        btnqx.Content = "查看";
                    else this.btnqx.Content = "增加候选人";
                }
                if (qx == JinShenConst.ACTION_Candidate_Check)
                {
                    if (entity.Status == "人员审核通过" || entity.Status == "人员审核不通过")
                        btnqx.Content = "查看";
                    else this.btnqx.Content = "人员审核";
                }
                if (qx == JinShenConst.ACTION_Candidate_Evalution)
                    this.btnqx.Content = "民主测评及竞争上岗";
                if (qx == JinShenConst.ACTION_Candidate_Approval)
                    this.btnqx.Content = "人员核定";
            }

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            JinShen_MainInfo item = (sender as Button).Tag as JinShen_MainInfo;
            if (isqx == JinShenConst.ACTION_Solution_Modify)
            {
                //if (item.Status.Equals("审核通过"))
                //{
                //    SilverlightMessageBoxLibrary.Message.InfoMessage("审核通过不能进行编辑！");
                //    return;
                //}
                if (btnqx.Content.ToString() == "查看") _isck = true;
                EditJInshengDetailWindow window = new EditJInshengDetailWindow(item.ID, JinShenConst.ACTION_Solution_Modify,_orgid,_isck);
                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window.entity;
                        (sender as Button).Tag = window.entity;
                    }
                };
            }
            if (isqx == JinShenConst.ACTION_Solution_Check)
            {
                if (btnqx.Content.ToString() == "查看") _isck = true;
                PromotCheckWindow window = new PromotCheckWindow(item,false,_isck);
                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window._mainInfo;
                        (sender as Button).Tag = window._mainInfo;
                        if (window._mainInfo.Status == "审核通过" || window._mainInfo.Status == "审核不通过")
                            btnqx.Content = "查看";
                    }
                };
            }
            if (isqx == JinShenConst.ACTION_Candidate_New)
            {
                //if (item.Status.Equals("人员审核通过"))
                //{
                //    SilverlightMessageBoxLibrary.Message.InfoMessage("人员审核通过不能再次进行审核！");
                //    return;
                //}
                if (btnqx.Content.ToString() == "查看") _isck = true;
                PromotWindow window = new PromotWindow(item, "新增候选人", true,_isck);
                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window.entity;
                        (sender as Button).Tag = window.entity;
                    }
                };
            }
            if (isqx == JinShenConst.ACTION_Candidate_Check)   //人员审核
            {
                if (btnqx.Content.ToString() == "查看") _isck = true;
                PromotCheckWindow window = new PromotCheckWindow(item, true,_isck);
                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window._mainInfo;
                        (sender as Button).Tag = window._mainInfo;
                        if (window._mainInfo.Status == "人员审核通过" || window._mainInfo.Status == "人员审核不通过")
                         btnqx.Content = "查看";
                    }
                };
            }
            if (isqx == JinShenConst.ACTION_Candidate_Evalution)
            {
                CandidatorCheckWindow window = new CandidatorCheckWindow(item,_bm,_isck);
                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window._MainInfo;
                        (sender as Button).Tag = window._MainInfo;
                    }
                };
            }
            if (isqx == JinShenConst.ACTION_Candidate_Approval)
            {
                ChooseCandidatorWindow window = new ChooseCandidatorWindow(item,_isck);

                window.Show();
                window.Closed += (sender1, e1) =>
                {

                    if (window.DialogResult == true && window.ReturnTrue == true)
                    {
                        ReturnTrue = true;
                        this.DataContext = "";
                        this.DataContext = window._MainInfo;
                        (sender as Button).Tag = window._MainInfo;
                    }
                };
            }
            
        }

        
    }
}
